  <template> 
   <div class="JNPF-common-layout"> 
    <div class="JNPF-common-layout-center"> 
     <el-row class="JNPF-common-search-box" :gutter="16"> 
      <el-form @submit.native.prevent="">
		<el-col :span="6">
			<el-form-item label="预案名称">
				<el-input v-model="query.yamc" placeholder="预案名称" clearable  />
			</el-form-item>
		</el-col>
		<el-col :span="6">
			<el-form-item label="所属部门">
				<el-select filterable v-model="query.sybm" placeholder="所属部门" clearable >
					<el-option v-for="(item, index) in sybmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id"  />
				</el-select>
			</el-form-item>
		</el-col>
		<el-col :span="6">
			<el-form-item label="预案级别">
				<el-select v-model="query.yajb" placeholder="预案级别" clearable >
					<el-option v-for="(item, index) in yajbOptions" :key="index" :label="item.fullName" :value="item.id"  />
				</el-select>
			</el-form-item>
		</el-col>

        <el-col :span="6"> 
            <el-form-item> 
                <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button> 
                <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button> 

            </el-form-item> 
       </el-col> 
      </el-form> 
     </el-row> 
     <div class="JNPF-common-layout-main JNPF-flex-main"> 
      <div class="JNPF-common-head"> 
       <div> 
		 <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
		 新增
		 </el-button>
		 <el-button type="text" icon="el-icon-download" @click="exportData()">
		 导出
		 </el-button>

       </div> 
       <div class="JNPF-common-head-right"> 
        <el-tooltip effect="dark" content="刷新" placement="top"> 
         <el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false" @click="reset()" /> 
        </el-tooltip> 
        <screenfull />
       </div> 
      </div> 
      <JNPF-table v-loading="listLoading" :data="list">
		<el-table-column prop="yamc" label="预案名称" align="left" />
		<el-table-column label="所属部门"  prop="sybm" algin="left">
			<template slot-scope="scope">{{ scope.row.sybm | dynamicText(sybmOptions) }}</template>
		</el-table-column>
		<el-table-column prop="yalx" label="预案类型" align="left" />
		<el-table-column prop="wxygl" label="危险源关联" align="left" />
		<el-table-column label="预案级别"  prop="yajb" algin="left">
			<template slot-scope="scope">{{ scope.row.yajb | dynamicText(yajbOptions) }}</template>
		</el-table-column>
		<el-table-column label="编写人"  prop="bxr" algin="left">
			<template slot-scope="scope">{{ scope.row.bxr | dynamicText(bxrOptions) }}</template>
		</el-table-column>
		<el-table-column label="编写部门"  prop="bxbm" algin="left">
			<template slot-scope="scope">{{ scope.row.bxbm | dynamicText(bxbmOptions) }}</template>
		</el-table-column>
		<el-table-column prop="fbssrq" label="发布实施日期" align="left" />
    <el-table-column label="执行状态"  prop="zxzt" align="left" >
		<template slot-scope="scope">
            <el-button type="text" v-if="scope.row.zxzt == 0 || scope.row.zxzt == 2" @click="zhiX(scope.row.id)">
            执行
            </el-button>
            <el-button type="text" v-if="scope.row.zxzt == 1" @click="stop(scope.row.id)">
            停止
            </el-button>
		</template>
	</el-table-column>
	<el-table-column label="操作" fixed="right" width="150">
		<template slot-scope="scope">
		<el-button type="text" @click="addOrUpdateHandle(scope.row.id)" >
		编辑
		</el-button>
		<el-button type="text" @click="handleDel(scope.row.id)" class="JNPF-table-delBtn">
		删除
		</el-button>
		<el-button type="text" @click="addOrUpdateHandle(scope.row.id,true)" >
		详情
		</el-button>
		</template>
	</el-table-column>
       
      </JNPF-table> 
      <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />

     </div> 
    </div> 
    <JNPFForm v-if="formVisible" ref="JNPFForm" @refresh="refresh" /> 
    <exportbox v-if="exportBoxVisible" ref="ExportBox" @download="download" /> 
   </div> 
</template> 
  <script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './Form'
    import ExportBox from './ExportBox'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {JNPFForm, ExportBox},
        data() {
            return {
                    showAll: false,
                query: {
					yamc:undefined,
					sybm:undefined,
					yajb:undefined,

                },
                defaultProps: {
                    children: 'children',
                    label: 'fullName'
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
                columnList: [
					{prop: 'yamc', label: '预案名称'},
					{prop: 'sybm', label: '所属部门'},
					{prop: 'yalx', label: '预案类型'},
					{prop: 'wxygl', label: '危险源关联'},
					{prop: 'yajb', label: '预案级别'},
					{prop: 'bxr', label: '编写人'},
					{prop: 'bxbm', label: '编写部门'},
					{prop: 'fbssrq', label: '发布实施日期'},

                ],
				sybmOptions:[],
				yajbOptions:[{"fullName":"综合预案","id":"综合预案"},{"fullName":"专项预案","id":"专项预案"},{"fullName":"现场处置方案","id":"现场处置方案"}],
				bxrOptions:[],
				bxbmOptions:[],
				ztOptions:[{"fullName":"现行","id":"现行"},{"fullName":"作废","id":"作废"}],
				yjdwOptions:[],
				yjwzOptions:[],
				yjryOptions:[],

            }
        },
        computed: {},
        created() {
                this.initData();
		this.getSybmOptions();
		this.getBxrOptions();
		this.getBxbmOptions();
		this.getYjdwOptions();
		this.getYjwzOptions();
		this.getYjryOptions();

        },
        methods: {
		getSybmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.sybmOptions = res.data
			})
		},
		getBxrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.bxrOptions = res.data
			})
		},
		getBxbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.bxbmOptions = res.data
			})
		},
		getYjdwOptions()
		{
			previewDataInterface('1bc1b1e0138a4767835729e9f531990e').then(res => {
				this.yjdwOptions = res.data
			})
		},
		getYjwzOptions()
		{
			previewDataInterface('b5c62631d0534c6e876dff010edb4ae6').then(res => {
				this.yjwzOptions = res.data
			})
		},
		getYjryOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.yjryOptions = res.data
			})
		},

            initData() {
                this.listLoading = true;
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    url: `/api/System/YJYAXX`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
            handleDel(id) {
                this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    type: 'warning'
                }).then(() => {
                    request({
                        url: `/api/System/YJYAXX/${id}`,
                        method: 'DELETE'
                    }).then(res => {
                        this.$message({
                            type: 'success',
                            message: res.msg,
                            onClose: () => {
                                this.initData()
                            }
                        });
                    })
                }).catch(() => {
                });
            },
            addOrUpdateHandle(id,isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail)
                })
            },
            exportData() {
                this.exportBoxVisible = true
                this.$nextTick(() => {
                    this.$refs.ExportBox.init(this.columnList)
                })
            },
            download(data) {
                let query = {...data, ...this.listQuery, ...this.query}
                request({
                    url: `/api/System/YJYAXX/Actions/Export`,
                    method: 'POST',
                    data: query
                }).then(res => {
                    if (!res.data.url) return
                    window.location.href = this.define.comUrl + res.data.url
                    this.$refs.ExportBox.visible = false
                    this.exportBoxVisible = false
                })
            },
            search() {
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
					currentPage: 1,
					pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            zhiX(id){
                request({
                    url: '/api/System/YJYAXX/Actions/YAZX/' + id + '/' + '1',
                    method: 'GET',
                }).then(res => {
                    if(res.code == '200'){
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () =>{
                               this.initData();
                            }
                        })  
                    }
                })
            },
            stop(id){
                request({
                    url: '/api/System/YJYAXX/Actions/YAZX/' + id + '/' + '2',
                    method: 'GET',
                }).then(res => {
                    if(res.code == '200'){
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () =>{
                               this.initData();
                            }
                        })  
                    }
                })
            }
        }
    }
</script>